Marquee #7: Multiple Messages

This script loads changing messages at three-second intervals.

Discussion

The createMsgs() populates the msgs array. The msgcounter keeps track of the current message. It uses modulus to flip back to zero when it reaches the maximum count. Here, five seconds is created by "ticking" the watch 10times over half-second intervals because on some platforms, the status line resets at mouse moves.
    
// populate the message array
function createMsgs()
{
    this[0] = "YOUR MESSAGE #1"
    this[1] = "YOUR MESSAGE #2"
    this[2] = "YOUR MESSAGE #3"
    this[3] = "YOUR MESSAGE #4"
    this[4] = "YOUR MESSAGE #5"
    return this
}
var msgs=createMsgs()
var msgcounter = 0
var ticks = 0
var MSGS = 5

// Change the message if we've "ticked" out
function setMessage()
{
    // redraw the current status
    window.status = msgs[msgcounter]
    
    // tick.  See if it is time to change the message
    ticks++
    if (ticks == 10)
    {
        msgcounter = (msgcounter + 1) % MSGS
        ticks = 0
    }
    
    // set the next time out
    JSCTimeOutID = window.setTimeout('setMessage()',500)
}
Copyright ©2000 by Charles River Media, All Rights Reserved